package com.guigu.utils;

import com.guigu.pojo.design.DFile;
import com.guigu.pojo.design.DModule;
import com.guigu.pojo.manufacture.MApply;
import com.guigu.pojo.manufacture.MDesignProcedure;
import com.guigu.pojo.manufacture.MManufacture;
import com.guigu.pojo.stock.SCell;
import com.guigu.pojo.stock.SGather;
import com.guigu.pojo.stock.SPay;

import java.util.Date;

public class CodeUtils {

    public String getDateCode(){
        Date date = new Date();
        String year = String.valueOf(date.getYear());
        String month = String.valueOf((date.getMonth()+1)<10?"0"+date.getMonth():date.getMonth());
        String day = String.valueOf(date.getDate()<10?"0"+date.getDate():date.getDate());
        String code = year+month+day;
        return code;
    }
    public String getProductCode(String firstId, String secondId, String thirdId, DFile endFile){
        if(endFile==null){
            String code = "100"+firstId+secondId+thirdId+"000001";
            return code;
        }
        String productId = endFile.getProductId();
        String str = productId.substring(productId.length()-6, productId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "100"+firstId+secondId+thirdId+str3;
        return code;
    }

    public String getMaterialCode(DModule endModule){
        if(endModule==null){
            String code = "200"+getDateCode()+"0001";
            return code;}
        if(endModule.getProductId()==null){
            String code = "200"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "200" + getDateCode() + "0001";
            return code;
        }
        String designId = endModule.getDesignId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "200" + getDateCode() + str3;
        return code;
    }
    public String getProcessCode(MDesignProcedure endDesignProcedure){
        if(endDesignProcedure==null){
            String code = "201"+getDateCode()+"0001";
            return code;
        }
        if(endDesignProcedure.getProductId()==null){
            String code = "201"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "201" + getDateCode() + "0001";
            return code;
        }
        String designId = endDesignProcedure.getDesignId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "201" + getDateCode() + str3;
        return code;
    }
    public String getProduceCode(MApply endApply){
        if(endApply==null){
            String code = "300"+getDateCode()+"0001";
            return code;
        }
        if(endApply.getProductId()==null){
            String code = "300"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "300" + getDateCode() + "0001";
            return code;
        }
        String designId = endApply.getApplyId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "300" + getDateCode() + str3;
        return code;
    }
    public String getManufactureId(MManufacture manufacture){
        if(manufacture==null){
            String code = "301"+getDateCode()+"0001";
            return code;
        }
        if(manufacture.getManufactureId()==null){
            String code = "301"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "301" + getDateCode() + "0001";
            return code;
        }
        String designId = manufacture.getManufactureId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "301" + getDateCode() + str3;
        return code;
    }
    public String getStockCode(SCell endCell){
        if(endCell==null){
            String code = "400"+getDateCode()+"0001";
            return code;
        }
        if(endCell.getProductId()==null){
            String code = "400"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "400" + getDateCode() + "0001";
            return code;
        }
        String designId = endCell.getStoreId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "400" + getDateCode() + str3;
        return code;
    }
    public String getStorageCode(SGather endGather){
        if(endGather==null){
            String code = "401"+getDateCode()+"0001";
            return code;
        }
        if(endGather.getGatherId()==null){
            String code = "401"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "401" + getDateCode() + "0001";
            return code;
        }
        String designId = endGather.getGatherId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "401" + getDateCode() + str3;
        return code;
    }
    public String getOutboundCode(SPay endPay){
        if(endPay==null){
            String code = "402"+getDateCode()+"0001";
            return code;
        }
        if(endPay.getPayId()==null){
            String code = "402"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "402" + getDateCode() + "0001";
            return code;
        }
        String designId = endPay.getPayId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "402" + getDateCode() + str3;
        return code;
    }

    public String getGatherboundCode(SGather endGather){
        if(endGather==null){
            String code = "402"+getDateCode()+"0001";
            return code;
        }
        if(endGather.getGatherId()==null){
            String code = "402"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "402" + getDateCode() + "0001";
            return code;
        }
        String designId = endGather.getGatherId();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "402" + getDateCode() + str3;
        return code;
    }

    public String getNewKindId(String endKindId) {

        int id = Integer.parseInt(endKindId);
        id++;
        if (id < 10) {
            String ID = id + "";
            String str = "";
            for (int i = 0; i < endKindId.length() - ID.length(); i++) {
                str = "0" + ID;
            }
            return str;
        }else{
            return id+"";
        }
    }

}
